package com.java2007.service.impl;

import com.java2007.mapper.AdminMapper;
import com.java2007.pojo.Admin;
import com.java2007.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


/**
 * @author zy
 * @version V1.0
 * @date 2021/03/10
 */
@Service
@Transactional
public class AdminServiceImpl implements AdminService {

    @Autowired
    private AdminMapper adminMapper;

    @Override
    public Admin login(String adminName, String adminPassword) {
        Admin admin = adminMapper.findByAdminName(adminName);
        if (admin != null){
            if (admin.getAdminPassword().equals(adminPassword)) {
                return admin;
            } else {
                throw new RuntimeException("账户或密码错误！！！");
            }
        } else {
            throw new RuntimeException("账户不存在，请联系管理员！");
        }
    }

    @Override
    public void updatePwd(String reNewPasswd, Long adminId) {
        adminMapper.updatePassword(reNewPasswd,adminId);
    }
}
